package cn.ronghuanet.car.controller;

import cn.ronghuanet.car.service.ICarDetailService;
import cn.ronghuanet.car.domain.CarDetail;
import cn.ronghuanet.car.query.CarDetailQuery;
import cn.ronghuanet.base.util.AjaxResult;
import cn.ronghuanet.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/carDetail")
public class CarDetailController {
    @Autowired
    public ICarDetailService carDetailService;


    /**
     * 保存和修改公用的
     * @param carDetail  传递的实体
     * @return Ajaxresult转换结果
     */
    @PostMapping
    public AjaxResult addOrUpdate(@RequestBody CarDetail carDetail){
        if( carDetail.getId()!=null)
            carDetailService.update(carDetail);
        else
            carDetailService.insert(carDetail);
        return AjaxResult.success();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult deleteOne(@PathVariable("id") Long id){
        carDetailService.delete(id);
        return AjaxResult.success();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable("id")Long id)
    {
        CarDetail carDetail = carDetailService.selectById(id);
        return AjaxResult.success(carDetail);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult list(){

        List< CarDetail> list = carDetailService.selectAll();
        return AjaxResult.success(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PutMapping
    public AjaxResult queryPage(@RequestBody CarDetailQuery query)
    {
        PageInfo<CarDetail> pageList = carDetailService.pageList(query);
        return AjaxResult.success(pageList);

    }

    /**
   * 批量删除
   * @return
   */
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        carDetailService.batchDelete(ids);
        return AjaxResult.success();
    }
}
